//
//  LoginViewController.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "LoginViewController.h"
#import "LogInView.h"
#import "MSGLogInViewController.h"
#import "ForgetPassWordViewController.h"
#import "RegisterViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController
{
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
}
#pragma mark
#pragma mark - 搭建界面
- (void)setupUI{
    self.title = @"用户登录";
    
    LogInView *logInView = [LogInView logIn];
    //block回调
    
    __weak LoginViewController *selfVC = self;
    
    logInView.CompleteBlock = ^(Users *us){
        //给全局单例对象赋值登录成功的用户信息
        [UserManager sharedManager].userInfo = us;
        
        if (selfVC.LogInCompleteBlock) {
            [MLDefaults setBool:YES forKey:kIsUserLoginKey];
            selfVC.LogInCompleteBlock(us);
        }
        [selfVC.navigationController popViewControllerAnimated:YES];
    };
    [self.view addSubview:logInView];
    [logInView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_topLayoutGuideBottom);
        make.leading.trailing.bottom.equalTo(self.view);
    }];
    
#pragma mark - 注册button被点击的监听通知
    [logInView addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventValueChanged];
}

#pragma mark
#pragma mark - button被点击的监听方法
- (void)clickButton:(LogInView *)logInView{
    
    NSInteger tag = logInView.tag;
    switch (tag) {
        case 1:
        {
            NSLog(@"1");
            MSGLogInViewController *MSGVC = [[MSGLogInViewController alloc]init];
            __weak LoginViewController *selfVC = self;
            MSGVC.CompleteBlock = ^(Users *us){
                if (self.LogInCompleteBlock) {
                    [MLDefaults setBool:YES forKey:kIsUserLoginKey];
                    selfVC.LogInCompleteBlock(us);
                }
                [selfVC.navigationController popViewControllerAnimated:YES];
            };
            [self.navigationController pushViewController:MSGVC animated:YES];
        }
            break;
        case 2:
        {
            NSLog(@"点击了-->注册新账号");
            RegisterViewController *registerVC = [[RegisterViewController alloc]init];
            [self.navigationController pushViewController:registerVC animated:YES];
        }
            break;
        case 3:
        {
            NSLog(@"点击了-->忘记密码");
            ForgetPassWordViewController *forgetVC = [[ForgetPassWordViewController alloc]init];
            [self.navigationController pushViewController:forgetVC animated:YES];
        }
            break;
        default:
            break;
    }

}







- (void)dealloc{
    
    NSLog(@"登录页面销毁");
}





@end














